﻿using System;
using Microsoft.CodeAnalysis;

namespace EasyDDD.Application.Generator
{
    [Generator(LanguageNames.CSharp)]
    public class MySourceGenerator : ISourceGenerator
    {
        public void Execute(GeneratorExecutionContext context)
        {
            var _namespace = "EasyDDD.AdminModule.Application";
            var _dbContex = "AdminModuleRepositoryDbContext";
            context.AddSource("CommandUnitOfWorkBehavior.cs",
                $$"""
                // <auto-generated/>
                namespace {{_namespace}}
                {
                    internal class CommandUnitOfWorkBehavior<TCommand, TResponse>({{_dbContex}} context)
                        : EasyDDD.Application.ICommandUnitOfWorkBehavior<TCommand, TResponse>
                        where TCommand : ICommandBase
                    {
                        public async Task<TResponse> Handle(TCommand request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
                        {
                            var response = await next();
                            await context.SaveUnitOfWorkAsync(cancellationToken);
                            return response;
                        }
                    }
                }
                """);

            throw new NotImplementedException();
        }

        public void Initialize(GeneratorInitializationContext context)
        {
            throw new NotImplementedException();
        }
    }
}
